import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * This class is add student UI
 */
public class AddStudentUI  extends JPanel {
	/**
	 * title for the current window  
	 */
	private JLabel lbltitle = null;
	/**
	 * Label for id
	 */
	private JLabel lblID = null;
	/**
	 * text field for  id 
	 */
	private JTextField TextID = null;
	/**
	 * button for add student
	 */
	private JButton btnAddStudent = null;
	/**
	 * back button 
	 */
	public JButton btnBack = null;
	/**
	 * help button 
	 */
	public JButton btnHelp = null;
	/**
	 * Variable  for student id
	 */
	private String studentID;	
	/**
	 * list of id  
	 */
	private String listID;
	private int type;
	/**
	* Constructs 
	*/
	public AddStudentUI (String lID, int t) {
		super();
		listID = lID;
		type = t;
		initialize();
	}
	
	private void initialize() {
		
		btnAddStudent = new JButton();
		/**
		 *  add student Implementation
		 */
		btnAddStudent.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				StudentList studentList = new StudentList(type,listID,studentID,Global.sem);  // I changed the constructor, incase we have problems, check here!
				SQL s = new SQL(studentList,13);
				s.accept();
				System.out.println("add student");
				TextID.setText(null);
			}
		});
		btnAddStudent.setBounds(new Rectangle(130, 230, 200, 25));
		btnAddStudent.setText("Add Student");
		this.add(btnAddStudent,null);
		this.setVisible(true);
		
		lblID = new JLabel("Student ID");
		lblID.setBounds(83, 60, 110, 14);
		this.add(lblID);	
			
		TextID = new JTextField();
		TextID.setBounds(new Rectangle(194, 60, 128, 25));
		TextID.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				studentID=TextID.getText();			
			}
		}
		);
		this.add(TextID,null);
		

		lbltitle = new JLabel("Add Student to List" + listID);
		lbltitle.setBounds(193, 28, 110, 14);

		this.setSize(400, 321);
		this.setLayout(null);
		
		this.add(lbltitle);
	
		btnBack = new JButton("Back");
		btnBack.setBounds(187, 283, 86, 25);
		this.add(btnBack,null);
		this.setVisible(true);
		/**
		 *  help button Implementation
		 */
		btnHelp = new JButton("Help");
		btnHelp.setBounds(390, 11, 80, 19);
		btnHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				  HelpWin help = new HelpWin ("Choose  one of the options");
				  System.out.println("user press Help button");
			}
		});
		this.add(btnHelp,null);

		this.setVisible(true);
		
	}
}